// import { Page } from "@/types/storeModule"
import { assign, cloneDeep } from 'lodash-es'

const state = {
    // 接口调用参数
    params: {
        page: {
            currentPage: 1,
            pageSize: 20,
            totalCount: 0,
            totalPage: 0,
            sortField: 'job_id',
            order: 'desc'
        },
        options: {}
    },
    roles: {}, // 权限
    apiName: 'monitorJob',
    privileges: [
        'monitor-job-add',
        'monitor-job-edit',
        'monitor-job-remove'
    ],
    // 列表data数据
    isLoading: false,
    tableData: [],
    searchData: [
        {
            id: 'entity.keyword',
            name: '关键字',
            type: 'text',
            hint: '任务名称、任务组名、调用目标字符串、cron执行表达式',
            defaultValue: ''
        }
    ],
    tableHeadList: [
        {
            label: '任务编号',
            prop: 'jobId',
            width: 80
        },
        {
            label: '任务名称',
            prop: 'jobName',
            width: 200
        },
        {
            label: '任务组名',
            prop: 'jobGroup',
            width: 100
        },
        {
            label: '调用目标字符串',
            prop: 'invokeTarget',
            width: 200
        },
        {
            label: 'cron执行表达式',
            prop: 'cronExpression',
            width: 100
        },
        {
            label: '状态',
            prop: 'runing',
            width: 80,
            slotName: 'runing'
        }
    ],
    logTableHeadList: [
        {
            label: '日志编号',
            prop: 'jobLogId',
            width: 80
        },
        {
            label: '任务名称',
            prop: 'jobName',
            width: 120
        },
        {
            label: '任务组名',
            prop: 'jobGroup',
            width: 150
        },
        {
            label: '调用目标字符串',
            prop: 'invokeTarget',
            width: 150
        },
        {
            label: '日志信息',
            prop: 'jobMessage',
            width: 150
        },
        {
            label: '执行状态',
            prop: 'status',
            width: 80,
            slotName: 'status'
        },
        {
            label: '异常信息',
            prop: 'exceptionInfo',
            width: 100
        },
        {
            label: '执行时间',
            prop: 'createTime',
            width: 180
        }
    ]
}

// getters
const getters = {}

// actions
const actions = {}

// mutations
const mutations = {
    // 更新页面搜索内容
    updateSearchData(state, payload: any[]) {
        state.searchData = payload
    },
    // 更新表格 loading 状态
    updateLoading(state, payload: boolean) {
        state.isLoading = payload
    },

    // 更新数据page
    updatePage(state, payload: any) {
        state.params.page = assign(state.params.page, payload)
    },

    // 更新数据Condition
    updateCondition(state, payload: any) {
        state.params.condition = cloneDeep(payload)
    },

    // 更新data数据
    updateTableData(state, payload: any[]) {
        state.tableData = cloneDeep(payload)
    },
    // 更新列表表头数据
    updateEditTableList(state, payload: any[]) {
        state.tableHeadList = payload
    },
    // 更新列表参数数据
    updateParams(state, payload: any) {
        state.params = Object.assign({}, state.params, payload)
    },
    // 更新权限
    updateRoles(state, payload: Record<string, boolean>) {
        state.roles = payload
    }
}

export default {
    namespaced: true,
    state,
    getters,
    actions,
    mutations
}
